package entity

import (
	"encoding/json"
	"time"
)

type GuildRecord struct {
	ID        int
	ServerID  int32
	GuildID   int32
	Type      int8
	Name      string `gorm:"size:255"`
	Name2     string `gorm:"size:255"`
	Data      []byte `gorm:"type:json"`
	CreatedAt time.Time

	Values []int32 `sql:"-"`
}

func (b *GuildRecord) AfterFind() error {

	if b.Values == nil {
		b.Values = make([]int32, 0)
	}
	_ = json.Unmarshal(b.Data, &b.Values)

	return nil
}

func (b *GuildRecord) BeforeSave() error {

	if b.Values == nil {
		b.Values = make([]int32, 0)
	}

	b.Data, _ = json.Marshal(b.Values)
	return nil
}

func (b *GuildRecord) BeforeUpdate() error {

	if b.Values == nil {
		b.Values = make([]int32, 0)
	}

	b.Data, _ = json.Marshal(b.Values)
	return nil
}
